/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.action.person;

import apus.action.Action;
import apus.action.ActionResult;
import apus.entity.Person;
import apus.entity.RealPerson;
import apus.persistence.PersonDAO;
import apus.services.ServiceLocator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author 21vek
 */
public class PersonDeleteAction implements Action {

    @Override
    public String getName() {
        return "person.delete";
    }

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
        if (request.getParameter("id") != null) {
            int id = Integer.parseInt(request.getParameter("id"));
            Person person = new RealPerson();
            person.setId(id);
            ServiceLocator.getService(PersonDAO.class).delete(person);
            request.getSession().setAttribute("win", request.getParameter("name")+" was removed");
        } else {
            request.getSession().setAttribute("fail", "Subscriber wasn't removed");
        }

        return ActionResult.redirect("person.list");
        
    }
}
